﻿/*
创建人：longb
日期：2022-09-26
描述：热处理记录js
*/
var page = {
    workflowstepid: getParam("id"),
    ContainerID: getParam("ContainerID"),
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/GongZhuangContainer/GZHeatRecordInfoHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        page.GetHeatRecordInfo();
    },
    //页面事件绑定
    bind: function () {
        //配套件信息
        $('#DrawingNoTabel').datagrid({
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            rownumbers: true,
            columns: [[
                    { checkbox: true, field: '' },
		            { field: 'DRAWINGNO', title: '图号', width: 120, align: 'center' },
                ]]
        });
    },
    //添加图号
    AddDrawingNo: function () {
        var DrawingNo = $('#DrawingNo').textbox('getValue');
        if (DrawingNo == "") { displayMessage("请输入图号名称,再进行操作"); return; }
        $('#DrawingNoTabel').datagrid('appendRow', {
            DRAWINGNO: DrawingNo
        });
    },
    //删除图号
    DeleteDrawingNo: function () {
        var rows = $('#DrawingNoTabel').datagrid('getChecked');
        if (rows.length == 0) { displayMessage("请选择图号记录,再进行操作"); return; }
        var ids = [];
        $.each(rows, function (index, item) {
            var iindex = $('#DrawingNoTabel').datagrid('getRowIndex', item);
            $('#DrawingNoTabel').datagrid('deleteRow', iindex);
            if (item.GZHEATRECORDINFODETAIL2ID != "") {
                ids.push(item.GZHEATRECORDINFODETAIL2ID);
            }
        })



    },
    //保存热处理记录
    SaveHeatRecordInfo: function () {
        var frdata = $('#SpecArgForm').serializeArray();
        var basedata = $('#BaseForm').serializeArray();
        var data = {};
        var data1 = {};
        $.each(frdata, function () {
            if (this.name.indexOf("1") != -1) {
                data1[this.name.replace('1', '')] = this.value
            } else {
                data[this.name] = this.value
            }
        });
        var DA = [];
        DA.push(data); DA.push(data1);
        var bdata = {};
        $.each(basedata, function () {
            bdata[this.name] = this.value
        });
        var rows = $('#DrawingNoTabel').datagrid('getRows');
        var param = {
            action: "SaveHeatRecordInfo",
            ContainerID:page.ContainerID,
            workflowstepid:page.workflowstepid,
            Base: JSON.stringify([bdata]),
            Spec: JSON.stringify(DA),
            DrawingNos: JSON.stringify(rows)
        };
        page.post(param, function (res) {
            if (res.Result) {
                page.GetHeatRecordInfo();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //查询热处理记录
    GetHeatRecordInfo: function () {
        var param = {
            action: "GetHeatRecordInfo",
            ContainerID: page.ContainerID,
            workflowstepid:page.workflowstepid
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                $('#BaseForm').form('load',res.DBDataSet.base[0])
                $('#DrawingNoTabel').datagrid('loadData',res.DBDataSet.dg);
                var formdata=res.DBDataSet.spec[0];
                if(res.DBDataSet.spec.length>1){
                    formdata.SHOVECHARGETEMPERATURE1=res.DBDataSet.spec[1].SHOVECHARGETEMPERATURE;
                    formdata.SHOVECHARGETIME1=res.DBDataSet.spec[1].SHOVECHARGETIME;
                    formdata.KEEPWARMTEMPERATURE1=res.DBDataSet.spec[1].KEEPWARMTEMPERATURE;
                    formdata.HEATTOTEMPERATURETIME1=res.DBDataSet.spec[1].HEATTOTEMPERATURETIME;
                    formdata.OUTCHARGETIME1=res.DBDataSet.spec[1].OUTCHARGETIME;
                    formdata.COOLANT1=res.DBDataSet.spec[1].COOLANT;
                }
                $('#SpecArgForm').form('load',formdata)
            }
        });
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});